package BDD.modeles;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 * @version 1.0.0
 * @author AZRIA Nouriel
 */
@Entity
public class Photo implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    /* LES ATTRIBUTS */
    @ManyToOne          // On peut avoir plusieurs photos dans un album
    private Album album; 
    @Column(length=100)
    private String url;
    @Column(length=100)
    private String alt;
    @OneToMany(mappedBy = "photo",cascade = {CascadeType.REMOVE})  // Une photo peut possèder plusieurs commentaires
    private List<Commentaire> commentaires = new ArrayList<>();

    
    /* LES CONSTRUCTEURS */
    
    public Photo() {
    }
    
    public Photo(Album album, String url, String alt) {
        this.album = album;
        this.url = url;
        this.alt = alt;
    }
    
    
    /* LES GETTERS/SETTERS */
    
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Album getAlbum() {
        return album;
    }

    public void setAlbum(Album album) {
        this.album = album;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getAlt() {
        return alt;
    }

    public void setAlt(String alt) {
        this.alt = alt;
    }
    
    public List<Commentaire> getCommentaires() {
        return commentaires;
    }
    
    /* LES METHODES */
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) id;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Photo)) {
            return false;
        }
        Photo other = (Photo) object;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "BDD.modeles.Photo[ id=" + id + " ]";
    }
    
    public void addCommentaires(Commentaire c) {  
        commentaires.add(c);  
    }  
  
    public void removeCommentaires(Commentaire c) {  
        commentaires.remove(c);  
    } 
    
}
